<template>
    <el-container>
        <el-header>
            <div class="right-panel-search">
                <div class="search-input">时间</div>
                <el-date-picker v-model="search.time_range" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" size="medium" style="width:250px" />
                <div class="search-input">部门</div>
                <el-cascader v-model="search.dept_id" :options="depts" :props="deptsProps" clearable></el-cascader>
                <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
                <el-button type="primary" icon="el-icon-printer" @click="addInput" v-auth="'wages.print'">打印工资明细</el-button>
                <el-button type="primary" @click="deleteData" v-auth="'wages.Payroll'">转工资单</el-button>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" :apiObj="apiObj" @selection-change="selectionChange" stripe remoteSort remoteFilter border :params="query">
                <el-table-column type="selection" width="40"></el-table-column>
                <el-table-column label="部门" prop="needle_seed_name" align="center"></el-table-column>
                <el-table-column label="岗位" prop="needle_seed_name" align="center"></el-table-column>
                <el-table-column label="工号" prop="needle_seed_name" align="center"></el-table-column>
                <el-table-column label="姓名" prop="wool_seed" align="center"></el-table-column>
                <el-table-column label="合计工资" prop="maintenance_name" align="center"></el-table-column>
                <el-table-column label="操作" fixed="right" align="center" width="80">
                    <template #default="scope">
                        <el-button-group style="display:flex;flex-direction:column">
                            <el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)" v-auth="'wages.show'">查看明细</el-button>
                            <el-button text type="primary" size="small" @click="table_detial(scope.row, scope.$index)" v-auth="'wages.deduction'">补扣</el-button>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>
    <save v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save = false" draggable></save>
</template>
<script>
import save from './save.vue';

export default {
  components: { save },
	name: 'user',
	data() {
		return {
            dialog:{
                save:false
            },
			group: [],
			apiObj: this.$API.produce.workshop.scanRecord.list,
            query:{
                is_abnormal:1,
            },
			selection: [],
			search: {
				time_range: [this.getFirstDayOfMonth(), this.getLastDayOfMonth()],
				keyword: null,
                supplier_id:null,
                creator:null,
                order_no:null,
			},
            produce_no:"",
            isSaveing: false,
            depts: [],
			deptsProps: {
				value: "id",
				checkStrictly: true
			},
		}
	},
	mounted() {
        this.getDept()
    },
	methods: {
        getFirstDayOfMonth() {
            const currentDate = new Date();
            const firstDay = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1);
            return firstDay;
        },
        getLastDayOfMonth() {
            const currentDate = new Date();
            const lastDay = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0);
            return lastDay;
        },
        // 手动录入
        table_show(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('show').setData(row);
			})
		},
		//搜索
        upsearch() {
            this.$refs.table.upData(this.search)
		},
        deleteData(){
            console.log('删除');
        },
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			} else if (mode == 'set') {
				this.$refs.table.refresh()
			}
		},
        // 获取部门
        async getDept() {
			var res = await this.$API.system.dept.list.get();
			this.depts = res.data;
		},
	}
}
</script>

<style>
.search-input {
	width: auto;
	font-size: 14px;
}
</style>